package com.parent.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author yan
 * @Date 2024/5/14 0014 10:57
 * @Description
 */
@Component
public class CommonContext implements ApplicationContextAware {
    public static ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static<T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }
}
